package com.itheima.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author Anomaly
 * @date 2023/2/12 18:52
 */
public class StarAgent {
    public static Skill getProxy(Star star) {
        return (Skill) Proxy.newProxyInstance(star.getClass().getClassLoader(),
                star.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("InvocationHandler()执行。。" + method.getName() + "被调用");
                        Object rs = method.invoke(star, args);
                        System.out.println("InvocationHandler()执行结束。。");
                        return rs;
                    }
                });
    }
}
